package com.zzl.rabbitmq.ack;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.zzl.rabbitmq.utils.RabbitMqUtils;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * Title: AckProvider.class<br>
 * Description: <br>
 * Copyright (c)  2021    <br>
 * Create DateTime: 2021/7/7 11:22 <br>
 *
 * @author zhuangzhuangliang
 */
public class AckProvider {

    public static final String QUEUE_NAME = "ack_queue";

    public static void main(String[] args) throws  Exception {
        long begin = System.currentTimeMillis();
        Channel channel = RabbitMqUtils.getChannel();
        //durable 队列持久化
        channel.queueDeclare(QUEUE_NAME,true,false,false,null);
        String msg = "ack provider;";

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            msg = scanner.next();
            //消息持久化 MessageProperties.PERSISTENT_TEXT_PLAIN
            channel.basicPublish("",QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,msg.getBytes(StandardCharsets.UTF_8));
            long end = System.currentTimeMillis() - begin;
            System.out.println(msg+" 发送完成 耗时: "+ end);
        }

        System.out.println("处理结束");
    }
}
